package Control;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import Model.Wereld;

public class Start extends JFrame {
	private JButton start, uitleg, credits, exit;
	private JLabel titel;
	private GridLayout layout;
	private Wereld wereld;
	private MenuHandler menuHandler;
	private Font font;
	private Apl apl;
	private JPanel panel;

	public Start(Wereld wereld) {
		panel = new JPanel();

		setVisible(true);
		setTitle("Helicoptergame Saxion feb 2011");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(800, 800);

		this.wereld = wereld;
		layout = new GridLayout(6, 3);
		layout.setHgap(5);
		layout.setVgap(15);
		panel.setBackground(Color.BLACK);
		panel.setLayout(layout);

		font = new Font("Serif", Font.BOLD, 37);

		menuHandler = new MenuHandler();
		start = new JButton("Start");
		start.setFont(font);
		start.setForeground(Color.GREEN);
		start.setBackground(Color.GREEN.darker().darker().darker().darker());
		start.addActionListener(menuHandler);

		uitleg = new JButton("Uitleg");
		uitleg.setFont(font);
		uitleg.setForeground(Color.GREEN);
		uitleg.setBackground(Color.GREEN.darker().darker().darker().darker());
		uitleg.addActionListener(menuHandler);

		credits = new JButton("Credits");
		credits.setFont(font);
		credits.setForeground(Color.GREEN);
		credits.setBackground(Color.GREEN.darker().darker().darker().darker());
		credits.addActionListener(menuHandler);

		exit = new JButton("Exit");
		exit.setFont(font);
		exit.setForeground(Color.GREEN);
		exit.setBackground(Color.GREEN.darker().darker().darker().darker());
		exit.addActionListener(menuHandler);

		titel = new JLabel("HelicopterGame");
		titel.setFont(font);
		titel.setForeground(Color.GREEN);

		panel.add(new JLabel(""));
		panel.add(titel);
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));
		panel.add(start);
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));
		panel.add(uitleg);
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));
		panel.add(credits);
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));
		panel.add(exit);
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));
		panel.add(new JLabel(""));

		setContentPane(panel);
	}

	public void setMenu(boolean zichtbaar) {
		this.setVisible(zichtbaar);
	}

	class MenuHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == start) {
				@SuppressWarnings("unused")
				JFrame frame = new Apl(wereld);
				setMenu(false);
			}
			if (e.getSource() == uitleg) {
				JPanel panel = new Uitleg();
				JFrame frame = new JFrame();
				frame.setSize(800, 800);
				frame.setTitle("Uitleg Helicoptergame");
				frame.setVisible(true);
				frame.setContentPane(panel);

			}
			if (e.getSource() == credits) {
				JPanel panel = new Credits();
				JFrame frame = new JFrame();
				frame.setSize(200, 200);
				frame.setTitle("Credits");
				frame.setVisible(true);
				frame.setContentPane(panel);
			}
			if (e.getSource() == exit) {
				System.exit(1);
			}
		}
	}

	static class Uitleg extends JPanel {
		private BufferedImage image;

		public Uitleg() {
			File file = new File("Data/back.png");
			try {
				image = ImageIO.read(file);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		public void paintComponent(Graphics g) {
			g.drawImage(image, 0, 0, null);
		}
	}

	static class Credits extends JPanel {
		private JLabel made, naam1, naam2, klas, datum;

		public Credits() {
			setLayout(new GridLayout(6,1));
			setBackground(Color.GREEN);
			made = new JLabel("Made by:");
			naam1 = new JLabel("Harm Koster");
			naam2 = new JLabel("Ken Veenstra");
			klas = new JLabel("klas: ein2b");
			datum = new JLabel("februari 2011");
			
			add(made);
			add(naam1);
			add(naam2);
			add(klas);
			add(datum);
		}
	}
}
